package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.SupplierBean;
import com.project.mapper.ISupplierMapper;
import com.project.service.ISupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class SupplierServiceImpl implements ISupplierService {
    @Autowired
    private ISupplierMapper mapper;

    @Override
    public IPage<SupplierBean> cutByItem(Integer pageNO, String sName, String sRange) {
        QueryWrapper<SupplierBean> qw = new QueryWrapper<>();
        if (sName != null && sName != "") {
            qw.like("s_sName", sName);
        }
        if (sRange != null && sRange != "") {
            qw.like("s_sRange", sRange);
        }
        return mapper.selectPage(new Page<>(pageNO, 3), qw);
    }

    @Override
    public SupplierBean findBySupplierId(Integer supplierId) {
        return mapper.selectById(supplierId);
    }

    @Override
    public void updateSupplier(Integer supplierId, String sLeader, String sLeaderPhone) {
        SupplierBean supplier = mapper.selectById(supplierId);
        supplier.setsLeader(sLeader);
        supplier.setsLeaderPhone(sLeaderPhone);
        mapper.updateById(supplier);
    }

    @Override
    public void addSupplier(SupplierBean supplier) {
        mapper.insert(supplier);
    }

    @Override
    public void addSupplierList(List<SupplierBean> supplierList) {
        mapper.addSupplierList(supplierList);
    }

    @Override
    public List<SupplierBean> findAllSupplier() {
        return mapper.selectList(null);
    }
}
